<%@page language="java" contentType="text/html"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="org.pomirkovany.beans.Item"%>
<jsp:useBean id="dataAccess" scope="application"
  class="org.pomirkovany.model.DataAccess"/>
<% String base = (String)application.getAttribute("base");
String imageURL = (String)application.getAttribute("imageURL");
%>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Browse Catalog</title>
  <link rel="stylesheet" href="/Cataloguer/css/cataloguer.css" type="text/css"/>
  </head>
<body>

<jsp:include page="header.jsp" flush="true"/>
<jsp:include page="SearchBar.jsp" flush="true"/>
<jsp:include page="typesmenu.jsp" flush="true"/>
<%     
  String categoryId = request.getParameter("id");
  String categoryName = null;
  if (categoryId != null && !categoryId.trim().equals("")) {
    try {
      categoryName = dataAccess.getCategoryName(categoryId);
      }
    catch(NumberFormatException e) {}
    }
	else{
	out.print("<p>Chose a category</p>");	
	}
  if (categoryName != null) {
  %>
    <div class="content">
      <p>Category: <strong><%=categoryName%></strong></p>
      <table>
        <tr>
          <th>Name</th>
          <th>Author</th>
          <th>Owner</th>
          <th>Date</th>
          <th>Borrowed</th>
          <th>Picture</th>
          <th>Location</th>
          <th>Rate</th>
          </tr>
          <form action="">
<%
        ArrayList items = dataAccess.getItemsInCategory(categoryId);
        Iterator iterator = items.iterator();
        while (iterator.hasNext()) {
          Item item = (Item)iterator.next();
          String pId = item.getId();
  %>
          <tr>
            <td><%=item.getName()%></td>
            <td><%=item.getAuthor()%></td>
            <td><%=item.getOwner()%></td>
            <td><%=item.getDate()%></td>
            <td><input type="checkbox" name="vehicle"
             <%if(item.isBorrowed()){%>
             checked<%}%> value="" disabled /></td>
            <td><img border="0" src="<%=imageURL + item.getPicture()%>" alt="no picture" width="90%" height="90%" /></td>

            <td><%=item.getLocation()%></td>
            <td><img border="0" src="images\<%=item.getRate()%>s.png" alt="no picture" width="90%" height="90%" /></td>
                        
            <td><a class="link1"
              href="<%=base%>?action=itemDetails&itemId=<%=pId%>">
              Details</a></td>
            </tr>
<%
          }
  %>
  </form>
  
        </table>
      </div>
<%
    }
  else {
	%><p class="error"></p><%
	}
%>
</body>
</html>
